﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Arcadium.GameEntities.Weapons;
using Arcadium.GameEntities.Projectiles;
using Microsoft.Xna.Framework.GamerServices;
using Arcadium.Audio;
using Microsoft.Xna.Framework.Net;
using Arcadium.Graphics;

namespace Arcadium.GameEntities
{
    class HandGun : Weapon
    {
        #region Field

        // Static members
        private static Texture2D texture;
        private static Vector2 textureOrigin;

        #endregion

        #region Properties

        public override Texture2D Texture
        {
            get { return texture; }
        }

        public override Vector2 TextureOrigin
        {
            get { return textureOrigin; }
        }

        public override float FirePower
        {
            get { return 2000; }
        }

        public override TimeSpan FiringRate
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region Initialization

        /// <summary>
        /// Constructs a new handgun.
        /// </summary>
        public HandGun(World world, Character character)
            : base(world, character)
        {
            //TODO: Add handgun-specific properties.
        }

        public static void LoadContent(ContentManager content)
        {
            texture = content.Load<Texture2D>("Gameplay\\Weapons\\handgun");
            textureOrigin = new Vector2(45, 0);
        }

        #endregion
        
        #region Draw

        /// <summary>
        /// Draws this handgun to the spriteBatch.
        /// </summary>
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            spriteBatch.Draw(texture, View.Adjust(character.Position), null, Color.White, 0, textureOrigin, View.ScreenScale,
                View.ToEffect(character.Direction), 0);
        }

        #endregion

        #region Public Methods

        public override void Shoot(NetworkGamer gamer, Vector2 position, int direction)
        {
            AudioManager.HandGun.Play();
            World.AddEntity(StandardBullet.Create(World, gamer, position, new Vector2(-direction * FirePower, 0)));
            World.AddEntity(StandardBullet.Create(World, gamer, position, new Vector2(direction * FirePower, 0)));
        }

        #endregion
    }
}
